// pages/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hidden: false,
    nohidden: true
  },
  money() {
    let name = getApp().globalData.usersname
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/money/money',
      })
    }
  },
  credit() {
    let name = getApp().globalData.usersname
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/user-credit/user-credit',
      })
    }
  },
  coupon() {
    let name = getApp().globalData.usersname
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/coupon/coupon',
      })
    }

  },
  customer() {

    let name = getApp().globalData.usersname
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/customer/customer',
      })
    }
  },
  out() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  login() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  profile(e) {
    // console.log(this.data.name)

    let name = this.data.name
    wx.navigateTo({
      url: '/pages/user-profile/user-profile?name=' + name + '',
    })

  },

  // 订单
  allorder() {
    let name = getApp().globalData.usersname
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/order-all/order-all',
      })
    }

  },
  payorder() {
    let name = getApp().globalData.usersname
    var condition = '待付款'
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/order-pay/order-pay?condition=' + condition + '',
      })
    }

  },
  deliverorder() {
    let name = getApp().globalData.usersname
    var condition = '待发货'
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/order-pay/order-pay?condition=' + condition + '',
      })
    }

  },
  shareorder() {
    let name = getApp().globalData.usersname
    var condition = '待分享'
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/order-pay/order-pay?condition=' + condition + '',
      })
    }

  },
  receivingorder() {
    let name = getApp().globalData.usersname
    var condition = '待收货'
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/order-pay/order-pay?condition=' + condition + '',
      })
    }

  },
  evaluateorder() {
    let name = getApp().globalData.usersname
    var condition = '待评价'
    if (!name) {
      console.log('抱歉，您还未登录！')
    } else {
      wx.navigateTo({
        url: '/pages/order-pay/order-pay?condition=' + condition + '',
      })
    }

  },

  User: function () {
    let name = getApp().globalData.usersname
    var that = this
    wx.request({
      url: 'http://localhost/shopping/users.php',
      method: 'GET',
      header: {
        'Content-Type': 'application/json'
      },
      data: {
        name: name
      },
      success: function (res) {
        // console.log(res.data)
        that.setData({
          img: res.data.users[0].img,
          name: res.data.users[0].petname,
        })
      },
      fail: function (res) {
        console.log("fail");
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {





  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let name = getApp().globalData.usersname
    var that = this;
    if (!name) {
      name = '抱歉，您还未登录'
      that.setData({
        name: name,
      })
    } else {
      that.User();
      that.setData({
        hidden: !that.data.hidden,
        nohidden: !that.data.nohidden
      })
    }

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    let name = getApp().globalData.usersname
    var that = this;
    if (!name) {
      name = '抱歉，您还未登录'
      that.setData({
        name: name,
      })
    } else {
      that.User();
      that.setData({
        hidden: !that.data.hidden,
        nohidden: !that.data.nohidden
      })
    }
  },


})